VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form2"
   ClientHeight    =   6810
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   13185
   LinkTopic       =   "Form2"
   ScaleHeight     =   6810
   ScaleWidth      =   13185
   StartUpPosition =   3  'Windows Default
   Begin VB.TextBox txtComm 
      Height          =   495
      Left            =   5760
      TabIndex        =   56
      Top             =   6000
      Width           =   1215
   End
   Begin VB.CommandButton cmdRun 
      Caption         =   "RunCommand"
      Height          =   495
      Left            =   4320
      TabIndex        =   55
      Top             =   6000
      Width           =   1215
   End
   Begin VB.CommandButton btnRun 
      Caption         =   "Run"
      Height          =   375
      Left            =   360
      TabIndex        =   52
      Top             =   5400
      Width           =   1095
   End
   Begin VB.TextBox Max2 
      Enabled         =   0   'False
      Height          =   375
      Index           =   1
      Left            =   7200
      TabIndex        =   33
      Top             =   5280
      Width           =   855
   End
   Begin VB.TextBox Max2 
      Enabled         =   0   'False
      Height          =   375
      Index           =   0
      Left            =   7200
      TabIndex        =   32
      Top             =   4680
      Width           =   855
   End
   Begin VB.TextBox Max1 
      Enabled         =   0   'False
      Height          =   375
      Left            =   7200
      TabIndex        =   31
      Top             =   4080
      Width           =   855
   End
   Begin VB.TextBox Opacity1 
      Enabled         =   0   'False
      Height          =   375
      Left            =   9360
      TabIndex        =   30
      Top             =   4080
      Width           =   855
   End
   Begin VB.TextBox KValue2 
      Enabled         =   0   'False
      Height          =   375
      Left            =   8280
      TabIndex        =   29
      Top             =   4680
      Width           =   855
   End
   Begin VB.TextBox Min2 
      Enabled         =   0   'False
      Height          =   375
      Left            =   6120
      TabIndex        =   28
      Top             =   4680
      Width           =   855
   End
   Begin VB.TextBox Min3 
      Enabled         =   0   'False
      Height          =   375
      Left            =   6120
      TabIndex        =   27
      Top             =   5280
      Width           =   855
   End
   Begin VB.TextBox KValue1 
      Enabled         =   0   'False
      Height          =   375
      Left            =   8280
      TabIndex        =   26
      Top             =   4080
      Width           =   855
   End
   Begin VB.TextBox KValue3 
      Enabled         =   0   'False
      Height          =   375
      Left            =   8280
      TabIndex        =   25
      Top             =   5280
      Width           =   855
   End
   Begin VB.TextBox Opacity2 
      Enabled         =   0   'False
      Height          =   375
      Left            =   9360
      TabIndex        =   24
      Top             =   4680
      Width           =   855
   End
   Begin VB.TextBox Opcity3 
      Enabled         =   0   'False
      Height          =   375
      Left            =   9360
      TabIndex        =   23
      Top             =   5280
      Width           =   855
   End
   Begin VB.TextBox AverageValue 
      Enabled         =   0   'False
      Height          =   375
      Left            =   10440
      TabIndex        =   22
      Top             =   4680
      Width           =   855
   End
   Begin VB.TextBox txtLimits 
      Enabled         =   0   'False
      Height          =   375
      Left            =   11760
      TabIndex        =   21
      Top             =   4680
      Width           =   855
   End
   Begin VB.TextBox Min1 
      Enabled         =   0   'False
      Height          =   375
      Left            =   6120
      TabIndex        =   20
      Top             =   4080
      Width           =   855
   End
   Begin VB.TextBox MeasureTimes 
      Height          =   375
      Left            =   1800
      TabIndex        =   19
      Top             =   5040
      Width           =   1575
   End
   Begin VB.TextBox Action 
      Alignment       =   2  'Center
      BackColor       =   &H000000FF&
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   13.5
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   615
      Left            =   1800
      TabIndex        =   18
      Text            =   "An ga"
      Top             =   4200
      Width           =   1575
   End
   Begin VB.TextBox MeasureScreen 
      Height          =   375
      Left            =   1800
      TabIndex        =   17
      Top             =   3600
      Width           =   1575
   End
   Begin VB.Frame Frame3 
      Caption         =   "Status"
      Height          =   3375
      Left            =   240
      TabIndex        =   16
      Top             =   3120
      Width           =   3375
      Begin VB.Label Label13 
         Caption         =   "Times"
         Height          =   375
         Left            =   240
         TabIndex        =   41
         Top             =   1920
         Width           =   1215
      End
      Begin VB.Label Label8 
         Caption         =   "Action"
         Height          =   375
         Left            =   240
         TabIndex        =   40
         Top             =   1320
         Width           =   975
      End
      Begin VB.Label Label3 
         Caption         =   "Measure Screen"
         Height          =   375
         Left            =   240
         TabIndex        =   39
         Top             =   480
         Width           =   1335
      End
   End
   Begin VB.ListBox Logger 
      Height          =   2010
      Left            =   4440
      TabIndex        =   14
      Top             =   720
      Width           =   8175
   End
   Begin VB.TextBox txtComPort 
      Height          =   285
      Left            =   1800
      TabIndex        =   4
      Text            =   "1"
      Top             =   480
      Width           =   615
   End
   Begin VB.TextBox txtComDataBit 
      Height          =   285
      Left            =   1800
      TabIndex        =   3
      Text            =   "8"
      Top             =   1920
      Width           =   615
   End
   Begin VB.TextBox txtParityBit 
      Height          =   285
      Left            =   1800
      TabIndex        =   2
      Text            =   "n"
      Top             =   1560
      Width           =   615
   End
   Begin VB.TextBox txtComBauRate 
      Height          =   285
      Left            =   1800
      TabIndex        =   1
      Text            =   "9600"
      Top             =   840
      Width           =   615
   End
   Begin VB.TextBox txtComStopBit 
      Height          =   285
      Left            =   1800
      TabIndex        =   0
      Text            =   "1"
      Top             =   1200
      Width           =   615
   End
   Begin VB.Frame Frame1 
      Caption         =   "Settings"
      Height          =   2655
      Left            =   240
      TabIndex        =   5
      Top             =   240
      Width           =   3375
      Begin VB.TextBox txtAddress 
         Height          =   285
         Left            =   2400
         TabIndex        =   53
         Text            =   "1"
         Top             =   600
         Width           =   615
      End
      Begin VB.TextBox txtTimer 
         Height          =   285
         Left            =   1560
         TabIndex        =   7
         Text            =   "60000"
         Top             =   2160
         Width           =   615
      End
      Begin VB.CommandButton btnUpdate 
         Caption         =   "Change Setting"
         Height          =   495
         Left            =   2280
         TabIndex        =   6
         Top             =   1920
         Width           =   975
      End
      Begin VB.Label Label6 
         Caption         =   "Address"
         Height          =   255
         Left            =   2400
         TabIndex        =   54
         Top             =   240
         Width           =   735
      End
      Begin VB.Label Label16 
         Caption         =   "TimerSetting"
         Height          =   255
         Left            =   240
         TabIndex        =   13
         Top             =   2160
         Width           =   1095
      End
      Begin VB.Label Label12 
         Caption         =   "COM Data bits"
         Height          =   255
         Left            =   240
         TabIndex        =   12
         Top             =   1800
         Width           =   1335
      End
      Begin VB.Label Label11 
         Caption         =   "COM Parity"
         Height          =   255
         Left            =   240
         TabIndex        =   11
         Top             =   1440
         Width           =   1095
      End
      Begin VB.Label Label10 
         Caption         =   "COM Stop bits"
         Height          =   255
         Left            =   240
         TabIndex        =   10
         Top             =   1080
         Width           =   1335
      End
      Begin VB.Label Label9 
         Caption         =   "COM Baurate"
         Height          =   255
         Left            =   240
         TabIndex        =   9
         Top             =   720
         Width           =   1335
      End
      Begin VB.Label Label7 
         Caption         =   "COM Port"
         Height          =   255
         Left            =   240
         TabIndex        =   8
         Top             =   360
         Width           =   855
      End
   End
   Begin VB.Frame Frame2 
      Caption         =   "Information"
      Height          =   2535
      Left            =   4320
      TabIndex        =   15
      Top             =   360
      Width           =   8415
   End
   Begin VB.Frame Frame4 
      Caption         =   "Measure Result"
      Height          =   2655
      Left            =   4320
      TabIndex        =   37
      Top             =   3240
      Width           =   8535
      Begin VB.Label Label24 
         Caption         =   "3"
         Height          =   375
         Left            =   600
         TabIndex        =   51
         Top             =   2040
         Width           =   1215
      End
      Begin VB.Label Label23 
         Caption         =   "2"
         Height          =   375
         Left            =   600
         TabIndex        =   50
         Top             =   1440
         Width           =   1095
      End
      Begin VB.Label Label22 
         Caption         =   "1"
         Height          =   375
         Left            =   600
         TabIndex        =   49
         Top             =   840
         Width           =   975
      End
      Begin VB.Label Label21 
         Caption         =   "Limits"
         Height          =   375
         Left            =   7440
         TabIndex        =   48
         Top             =   360
         Width           =   855
      End
      Begin VB.Label Label19 
         Caption         =   "Average Value"
         Height          =   375
         Left            =   6120
         TabIndex        =   46
         Top             =   360
         Width           =   855
      End
      Begin VB.Label Label18 
         Caption         =   "Opacity"
         Height          =   375
         Left            =   5040
         TabIndex        =   45
         Top             =   360
         Width           =   975
      End
      Begin VB.Label Label17 
         Caption         =   "k value"
         Height          =   375
         Left            =   3960
         TabIndex        =   44
         Top             =   360
         Width           =   975
      End
      Begin VB.Label Label15 
         Caption         =   "Max speed"
         Height          =   375
         Left            =   2880
         TabIndex        =   43
         Top             =   360
         Width           =   855
      End
      Begin VB.Label Label14 
         Caption         =   "Min speed"
         Height          =   375
         Left            =   1800
         TabIndex        =   42
         Top             =   360
         Width           =   975
      End
   End
   Begin VB.Label Label20 
      Caption         =   "Label20"
      Height          =   495
      Left            =   11640
      TabIndex        =   47
      Top             =   3720
      Width           =   975
   End
   Begin VB.Label Label5 
      Caption         =   "Label3"
      Height          =   375
      Left            =   0
      TabIndex        =   38
      Top             =   0
      Width           =   975
   End
   Begin VB.Label Label4 
      Caption         =   "Max Speed"
      Height          =   495
      Left            =   6120
      TabIndex        =   36
      Top             =   5520
      Width           =   1215
   End
   Begin VB.Label Label2 
      Caption         =   "k value"
      Height          =   495
      Left            =   7680
      TabIndex        =   35
      Top             =   5520
      Width           =   1215
   End
   Begin VB.Label Label1 
      Caption         =   "Min Speed"
      Height          =   495
      Left            =   4800
      TabIndex        =   34
      Top             =   5520
      Width           =   1215
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Const CmdGetingStatus As Byte = &H1
Const CmdGetingMesuringVal As Byte = &H2
Const CmdGetingStableStatus As Byte = &H3
Const CmdGetingAccelarateVal As Byte = &H4
Const CmdPerformingLinearity As Byte = &H5
Const CmdChangeMesurementScr As Byte = &H6
Const CmdChangeStableStatusScr As Byte = &H7
Const CmdChangeAccelerateScr As Byte = &H8
Const CmdStartOrStopStableStatus As Byte = &H9
Const CmdOilTempValue As Byte = &H10
Const CmdPerformOneTimeAccelerateTrigger As Byte = &HB
Const CmdAcceleratingCurve As Byte = &HF
Const CmdMainAccelerating As Byte = &HE


Dim dieselDevice As DieselClass
Private MSCommObj As New MSComm
Attribute MSCommObj.VB_VarHelpID = -1
Private mobjTmrObj As New vbAPITimerTools.APITimer
Attribute mobjTmrObj.VB_VarHelpID = -1
Private isRun As Boolean

Private Sub btnRun_Click()
    isRun = dieselDevice.IsRunning
    If isRun = False Then
        dieselDevice.StartRun
        btnRun.Caption = "Stop"
    Else
        dieselDevice.StopRun
        btnRun.Caption = "Start"
    End If
    
    'isRun = Not isRun
End Sub



Private Sub btnUpdate_Click()
    dieselDevice.HostAddress = txtAddress.Text
    dieselDevice.MSCommPort = txtComPort
    dieselDevice.MSComSettings = txtComBauRate.Text & "," & txtParityBit.Text & "," & txtComDataBit.Text & "," & txtComStopBit.Text
    
End Sub

Private Sub cmdRun_Click()
    Dim str As String
    Dim comm As Byte
    str = txtComm.Text
    
    If (str <> "") Then
        Select Case str
            Case "&H1"
                comm = &H1
            Case "&H2"
                comm = &H2
            Case "&H3"
                comm = &H3
            Case "&H4"
                comm = &H4
            Case "&H5"
                comm = &H5
            Case "&H6"
                comm = &H6
            Case "&H7"
                comm = &H7
            Case "&H8"
                comm = &H8
            Case "&H9"
                comm = &H9
            Case "&H10"
                comm = &H10
            Case "&HB"
                comm = &HB
            Case "&HF"
                comm = &HF
            Case "&HC"
                comm = &HC
            Case "&HE"
                comm = &HE
  
         Case Else
            comm = &H2
            ' do nothing
        End Select
            
        dieselDevice.SendCmd comm
    End If
    
End Sub

Private Sub Form_Initialize()
        Set dieselDevice = New DieselClass
        Set dieselDevice.MSCommObject = MSCommObj
        Set dieselDevice.TimerObject = mobjTmrObj
        Set frmForm = Me
End Sub

Private Sub Form_Terminate()
    'If Me.MSCommObj Is Nothing Then Set MSCommObj = New MSComm
    If Not dieselDevice Is Nothing Then
        Set dieselDevice.MSCommObject = Nothing
        Set dieselDevice.TimerObject = Nothing
        Set dieselDevice = Nothing
    End If
    Set MSCommObj = Nothing
    
End Sub

